<?php
/*
	提现
 * [JINYUN!] (C)2001-2099 Jinyunweb.com
 * This is NOT a freeware, use is subject to license terms
 * $Id: 2017-12-13 03:39:35 apple $
*/
defined('BY_JYA') or exit('error');
global $_RQ;
$_RQ['op']=$_RQ['op']?$_RQ['op']:'get';
cfc('core')->checklogin();
if($_RQ['op']=='get'){
	model('jy_weishop/member')->checklogin('','','',$_SESSION['onemerchid']);
	$this->session('buymid','');
	$this->session('merchid','');
	$this->model('model')->up_pass_sendlog();
	if($_RQ['merchid']){
		$_SESSION['onemerchid']=$_RQ['merchid'];
	}
	if($_SESSION['onemerchid']){
		$return['merchname']=pdo_getcolumn('jy_merch_user',array('id'=>$_SESSION['onemerchid']),'merchname');
	}
	$return['setting']['footernav']=$_SESSION['main_menus'];
	$_SESSION['forward_url']='jy_peimilk/member.index/';
	$return['item']=model('jy_merch/member')->getdetail($_SESSION['onemerchid']);
	$credit_types=credit_types();
	$pay=uni_setting('pay');
	foreach($credit_types as $k=>$cv){
		if($k>2){
			$prizeType[]=array(
				'id'=>$k,
				'title'=>$cv,
				'api'=>$pay['credit'.$k.'_api'],
				'data'=>$return['item']['credit'.$k],
			);
		}
	}
	$return['item']['credit_type']=$prizeType;
	$return['member']=cfc('core')->member_show($_SESSION['uid']);
	$return['member']['mid']=$_SESSION['uid'];
	$return['params']['type']=$_RQ['type']?:2;
	$return['feeurl']=$this->setting['feeurl']?:'jy_merchjifee/index//ismerch=1';
	$status0 = pdo_count('jy_weishop_order',array('sendtype'=>1,'merchid'=>$_SESSION['onemerchid'],'uniacid'=>$_SESSION['uniacid'],'mid'=>$_SESSION['uid'],'status'=>0,'deleted'=>0,'userdeleted'=>0));
	$status1 = pdo_count('jy_weishop_order',array('sendtype'=>1,'merchid'=>$_SESSION['onemerchid'],'uniacid'=>$_SESSION['uniacid'],'mid'=>$_SESSION['uid'],'status'=>1,'deleted'=>0,'userdeleted'=>0));
	$status2 = pdo_count('jy_weishop_order',array('sendtype'=>1,'merchid'=>$_SESSION['onemerchid'],'uniacid'=>$_SESSION['uniacid'],'mid'=>$_SESSION['uid'],'status'=>2,'deleted'=>0,'userdeleted'=>0));
	$status3 = pdo_count('jy_weishop_order',array('sendtype'=>1,'merchid'=>$_SESSION['onemerchid'],'uniacid'=>$_SESSION['uniacid'],'mid'=>$_SESSION['uid'],'status'=>3,'deleted'=>0,'userdeleted'=>0,'iscomment'=>0));
	$cartnums= pdo_getsum('jy_weishop_member_cart',array('mid'=> $_SESSION['uid'], 'uniacid' => $_SESSION['uniacid']),'total');
	$ratefee= pdo_getsum('jy_creditshop_log',array('paymerchid'=>$_SESSION['onemerchid'],'mid'=> $_SESSION['uid'], 'uniacid' => $_SESSION['uniacid'],'paystatus'=>1),'ratefee');
	$return['statics']=array(
		'status0'=>$status0,
		'status1'=>$status1,
		'status2'=>$status2,
		'status3'=>$status3,
		'cartnums'=>$cartnums,
		'ratefee'=>$ratefee
	);
	$status0 = pdo_count('jy_peimilk_sendlog',array('sendtype'=>1,'merchid'=>$_SESSION['onemerchid'],'uniacid'=>$_SESSION['uniacid'],'buymid'=>$_SESSION['uid'],'status'=>0));
	$status1 = pdo_count('jy_peimilk_sendlog',array('sendtype'=>1,'merchid'=>$_SESSION['onemerchid'],'uniacid'=>$_SESSION['uniacid'],'buymid'=>$_SESSION['uid'],'status'=>1));
	$status7 = pdo_count('jy_peimilk_sendlog',array('sendtype'=>1,'merchid'=>$_SESSION['onemerchid'],'uniacid'=>$_SESSION['uniacid'],'buymid'=>$_SESSION['uid'],'status'=>7));
	$return['statics2']=array(
		'status0'=>$status0,
		'status1'=>$status1,
		'status7'=>$status7,
	);
	$poster=plugin('jy_merch')->plugin_setting('poster'.$_SESSION['onemerchid']);
	$return['alllastnum'] = $this->model('order')->get_goodslastnum($_SESSION['uid'],$_SESSION['onemerchid']);
	if($_SESSION['onemerchid']){
		$return['goshopurl'] = 'jy_shopmilk/merchshop//onemerchid='.$_SESSION['onemerchid'];
	}else{
		$return['goshopurl'] = 'jy_shopmilk/index/';
	}
	$return['isposter']=$poster['isopen'];
	$return['jy_mjicai']=model('jy_merch/model')->get_groupset($_SESSION['onemerchid'],'jy_mjicai',true);
	$return['jy_area_jifee']=model('jy_merch/model')->get_groupset($_SESSION['onemerchid'],'jy_area_jifee',true);
	$return['jy_mshop2fee']=model('jy_merch/model')->get_groupset($_SESSION['onemerchid'],'jy_mshop2fee',true);
	$this->model('model')->up_allgoodsset($_SESSION['uid'],$_SESSION['onemerchid']);
	$return['params']['type']=$_RQ['type']?:1;
	set_html('title','会员中心');
	exi($return);
}
if($_RQ['op']=='list'){
	$allgoods=$this->model('order')->get_allgoods();
	$return['list']=$allgoods;
	exi($return);
}
if($_RQ['op']=='post'){
	$member=pdo_get('core_members',array('id'=>$_SESSION['uid']));
	$post=get_postdata();
	if(!$post['fee']){
		exi('请输入转账金额！','erroe');
	}
	if(!$post['mobile']){
		exi('请输入收款人账户/手机号！','erroe');
	}
	if(!$post['password']){
		exi('请输入支付密码！','erroe');
	}
	if($post['password']!=$member['paypassword']){
		exi('支付密码不正确！','erroe');
	}
	if($member['credit2']<$post['fee']){
		exi('转账额度不能大于，当前余额！','erroe');
	}
	$tomember=pdo_get('core_members',array('username'=>$post['mobile']));
	$tomid=$tomember['id'];
	if(!$tomid){
		$tomember=pdo_get('core_members',array('mobile'=>$post['mobile']));
		$tomid=$tomember['onemid']?:$tomember['id'];
	}
	if(!$tomid){
		exi('没找到收款人，转账失败！','erroe');
	}
	model('core/member')->cut_credit2($_SESSION['uid'],$post['fee'],'转账给:'.$post['mobile']);
	model('core/member')->add_credit2($tomid,$post['fee'],$member['username'].'的转账');
	exi('转账成功！');
}
if($_RQ['op']=='password'){
	$post=get_postdata();
	if(!$post['password']){
		exi('请输入支付密码！','erroe');
	}
	pdo_update('core_members',array('paypassword'=>$post['password']),array('id'=>$_SESSION['uid']));
	exi('设置成功！');
}